
layui.use(['jquery','layer','form','table','laydate','upload'],function(){
    var $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,upload = layui.upload;

    //普同检索
    form.on('submit(sub)',function(data){
        $.ajax({
            url: '/order/getGoodsOrders'
            ,data: {
                'orderPaymentChannel': data.field.orderPaymentChannel
                ,'orderSource': data.field.orderSource
                ,'orderType': 3
                ,'orderStatus': orderStatus
            }
            ,dataType: 'json'
            ,success:function(data){
                tableRender(data.data);
            }
        });
    });

    //按钮切换
    $(".btn").on("click","button",function () {
        $(this).removeClass("layui-btn-primary").siblings("button").addClass("layui-btn-primary");
    });
    $(".btn").on("mouseover","button",function () {
        $(this).css("border-color","#d2d2d2");
    });

    table.on('row(layuiTbale)',function (data) {
        localStorage.setItem("goodsOrderData",JSON.stringify(data.data));
    });

//状态变量
    var orderStatus = 2;

//未付款 赵 22/1/27
    $('#unpaid').click(function(){
        orderStatus = 2;
        getUsers(orderStatus);
    });
//已付款 赵 22/1/27
    $('#paid').click(function () {
        orderStatus = 3;
        getUsers(orderStatus);
    });
//待发货 赵 22/1/27
    $('#toBeShipped').click(function () {
        orderStatus = 4;
        getUsers(orderStatus);
    });
//已发货 赵 22/1/27
    $('#shipped').click(function () {
        orderStatus = 5;
        getUsers(orderStatus);
    });
//已签收 赵 22/1/27
    $('#signedIn').click(function () {
        orderStatus = 6;
        getUsers(orderStatus);
    });
//获取所有商品订单 22/1/27  赵
    getUsers(orderStatus);
    function getUsers(orderStatus){
        $.ajax({
            url: '/order/getGoodsOrders'
            ,data: {
                'orderType': 3
                ,'orderStatus': orderStatus
            }
            ,dataType: 'json'
            ,success:function(data){
                //渲染表格
                tableRender(data.data);
            }
        });
    }
//渲染表格22/1/27  赵
    function tableRender(data){
        table.render({
            elem: '#layuiTbale'
            ,data: data
            ,toolbar: '#toolutil'
            ,page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局
                ,limits:[10,15,20]
                ,first: true
                ,last: true
            }
            ,limit: 10
            ,cols: [[
                {checkbox: true}
                ,{type: 'numbers',title: '序号',align: 'center'}
                ,{field: 'nickname',title: '用户昵称',align: 'center'}
                ,{field: 'phone',title: '用户手机',align: 'center'}
                ,{field: 'orderStatus',title: '订单状态',align: 'center',templet:function(data){
                        if(data.orderStatus == 2){
                            return '未付款'
                        }else if(data.orderStatus == 3){
                            return '已付款'
                        }else{
                            return '数据错误';
                        }
                    }}
                ,{field: 'orderSource',title: '订单来源',align: 'center',templet:function(data){
                        if(data.orderSource == 2){
                            return '小程序';
                        }else if(data.orderSource == 3){
                            return 'app';
                        }
                    }}
                ,{field: 'productName',title: '商品名称',align: 'center'}
                ,{field: 'productDescription',title: '商品描述',align: 'center'}
                ,{field: 'orderPaymentChannel',title: '支付渠道',align: 'center',templet:function(data){
                        if(data.orderPaymentChannel == 2){
                            return '微信支付';
                        }else if(data.orderPaymentChannel == 3){
                            return '余额支付'
                        }
                    }}
                ,{title: '商家名称',align: 'center',templet:function(data){
                        return '思云';
                    }}
                ,{title: '操作',align: 'center',templet:function(data){
                        return '<a onclick="see('+data.orderId+')" style="color: #009688;">查看</a> ' +
                            '<a onclick="del('+data.orderId+')" style="color: #009688;">删除</a> '
                    }}
            ]]
        });
    }



//查看 22/1/27 赵
    see = function see(orderId){
        layer.open({
            type: 2
            ,title: '订单详情信息'
            ,area: ['1600px','900px']
            ,content: 'popup/goodsOrder-list-see.html'
            ,success: function (layero,index) {
                var goodsOrderData = JSON.parse(localStorage.getItem("goodsOrderData"));
                var objData = layero.find("iframe").contents();
                //订单编号
                objData.find("#orderLogisticsNumber").text(goodsOrderData.orderLogisticsNumber);
                //订单状态
                var orderStatus = goodsOrderData.orderStatus;
                if (orderStatus == 2){
                    objData.find("#orderStatus").text("未付款");
                }else if (orderStatus == 3){
                    objData.find("#orderStatus").text("已付款");
                } else{
                    objData.find("#orderStatus").text("数据错误");
                }
                //订单类型
                var orderType = goodsOrderData.orderType;
                if (orderType == 2){
                    objData.find("#orderType").text("视频");
                } else if (orderType == 3){
                    objData.find("#orderType").text("商品");
                }
                //订单来源
                var orderSource = goodsOrderData.orderSource;
                if (orderSource == 2){
                    objData.find("#orderSource").text("小程序");
                } else if (orderSource == 3){
                    objData.find("#orderSource").text("app");
                }
                //订单支付方式
                var orderPaymentChannel = goodsOrderData.orderPaymentChannel;
                if (orderPaymentChannel == 2){
                    objData.find("#orderPaymentChannel").text("微信支付");
                } else if (orderPaymentChannel == 3){
                    objData.find("#orderPaymentChannel").text("余额支付");
                }
                //商品价格
                objData.find("#originalpriceProduct").text(goodsOrderData.originalpriceProduct);
                //优惠金额
                objData.find("#couponPrice").text(goodsOrderData.originalpriceProduct - goodsOrderData.currentpriceProduct);
                //实付金额
                objData.find("#currentpriceProduct").text(goodsOrderData.currentpriceProduct);
                //用户账号
                objData.find("#account").text(goodsOrderData.account);
                //用户昵称
                objData.find("#nickname").text(goodsOrderData.nickname);
                //用户手机
                objData.find("#phone").text(goodsOrderData.phone);
                //用户邮箱
                objData.find("#email").text(goodsOrderData.email);
                //商品名称
                objData.find("#productName").text(goodsOrderData.productName);
                //商品分类
                objData.find("#title").text(goodsOrderData.title);
                //服务保证
                var ensure = goodsOrderData.ensure;
                if (ensure == 2){
                    objData.find("#ensure").text("退货无忧");
                }else if (ensure == 3){
                    objData.find("#ensure").text("快速退款");
                } else if (ensure == 4){
                    objData.find("#ensure").text("包邮");
                }
                //商品描述
                objData.find("#productDescription").text(goodsOrderData.productDescription);
                //商品图片
                if (goodsOrderData.mainImage != ''){
                    objData.find("#mainImage").attr("src",goodsOrderData.mainImage);
                }
            }
        })
    }

//删除 22/1/27 赵
    del = function del(orderId){
        layer.open({
            title: '删除订单'
            ,content: '确定删除此订单吗'
            ,btn: ['确定','取消']
            ,yes:function(index){
                //删除请求
                $.ajax({
                    url: '/order/delOrder'
                    ,data: {'orderId': orderId}
                    ,dataType: 'json'
                    ,success:function(data){
                        layer.close(index);
                        getUsers(orderStatus);
                        layer.msg('已删除');
                    }
                });
            }
            ,btn2:function(index){
                layer.close(index);
            }
        })
    }


//刷新22/1/27  赵
    refresh = function refresh(){
        location.reload();

    }

//返回22/1/27  赵



});
//返回首页
function backOff(){
    parent.jumpSystemHome();
}